import {api} from './libs/api.js';
let _self;
export const index =  {
	data() {
		return {
			optLock:false,
			dataList:[],
			tabSubItem:1,
			navList:api.navList,
			icons:[
				{type:"search",size:uni.upx2px(30)},
			],
			formField:[],
		}
	},
	
	mounted() {
		_self = this;
	},
	onReachBottom:function(e){
		this.params.page+=1;
		this.initData();
	},
	onLoad:function(option) {
		this.tabSubItem=option.show_type?option.show_type:1;
	},
	
	methods: {
		async initData(){
			uni.showLoading({title: '加载中'});
			this.params["show_type"]=this.tabSubItem;
			let orderInfo=await api.dataList(this.params);
			if(this.params.page==1){
				this.dataList=orderInfo["dataList"];
			}else{
				if(orderInfo["dataList"].length==0) this.params.page-=1;
				this.dataList.push.apply(this.dataList,orderInfo["dataList"]);
			}
			uni.hideLoading();
		},
		
		selectTab:function(event){
			this.params.page=1;
			this.tabSubItem=event.currentTarget.dataset.id;
			this.initData();
		},
		
		seachCustomer(){this.initData();},
		
		async deleteData(id){
			let retInfo=await api.deleteData({"id":id});
			if(retInfo=="success"){
				uni.showToast({icon:"none",title:"删除成功！"});
				setTimeout(function(){_self.initData();},2000);　　
			}
		},
		
		addPage(id){
			uni.navigateTo({
				url: "/packagePages/pages/customer/add/index?id="+id
			});
		}
			
	},
}